﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLayer;
using GameBase;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using GameInstrument;

namespace GameCharacter.AutoCharacter
{
    public class AutoCharacter : Character
    {
        public Vector2? Home { get; set; }
        private Random _random;
        private Vector2 _nextDirect;
        protected Random Random
        {
            get { return _random; }
            set { _random = value; }
        }
        public Vector2 NextDirect
        {
            get { return _nextDirect; }
            set { _nextDirect = value; }
        }

        public AutoCharacter(ContentManager content)
            : base(content)
        {
            Random = new Random();
            float x = (float)Random.NextDouble();
            float y = (float)Random.NextDouble();
            Velocity = Vector2.Normalize(new Vector2(x, y));
            Power = 3;
        }

        public override void GoToTarget(Vector2? target)
        {
            if (IsDying())
                return;
            if (target.HasValue)
            {
                base.GoToTarget(target);
            }
            else
            {
                int x = Random.Next();
                int y = Random.Next();
                Velocity = Vector2.Normalize(new Vector2(x, y)) * Speed();
            }
            UpdateToDirect(DirectToIndexDirect(Velocity));
        }

        public override List<Weapon> ReleasePowerAttack()
        {
            List<Weapon> weapons = null;
            if (!IsDying() && completePreparePowerRelease)
            {
                if (SoundAttack != null)
                    SoundAttack.Play();
                weapons = new List<Weapon>();
                for (int i = 0; i < Power; i++)
                {
                    var arch = new Arch(Content);
                    arch.Own = this;
                    arch.Power = ReleasePower();
                    arch.Direct = AttackTarget - this.Position;
                    arch.Position = this.Position;
                    weapons.Add(arch);
                }
                completePreparePowerRelease = false;

            }
            return weapons;
        }

    }
}
